home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gcctest / tests05.zoo / twrseek.c < prev   
C/C++ Source or Header  |  1993-03-02  |  954b  |  55 lines

  1. #include <stdio.h>
  2. int chk(got, expect, message)
  3. long got, expect;
  4. char *message;
  5. {
  6.     if(got != expect)
  7.     {
  8.         fprintf(stderr, "Expecting %ld Got %ld (%s)\n", expect, got, message);
  9.         return 1;
  10.     }
  11.     return 0;
  12. }
  13.  
  14. #define FILENAME "twrseek.tst"
  15. main()
  16. {
  17.         FILE *fp;
  18.         int status = 0;
  19.         long got;
  20.  
  21. #ifdef atarist
  22.         _binmode(1);
  23. #endif
  24.     if(!(fp = fopen(FILENAME,"w+")))
  25.         {
  26.         perror(FILENAME);
  27.         exit(1);
  28.         }
  29.  
  30.     got = fseek(fp,100L,0);
  31.         status |= chk(got, 0L, "fseek(fp, 100L, 0)");
  32.  
  33.     fwrite("a",1,1,fp);
  34.     got = ftell(fp);
  35.     status |= chk(got, 101L, "ftell(fp)");
  36.  
  37.     fseek(fp,200L,0);
  38.     fwrite("a",1,1,fp);
  39.     got = ftell(fp);
  40.     status |= chk(got, 201L, "ftell(fp) after fwrite");
  41.  
  42.     fseek(fp,100L,0);
  43.     got = fgetc(fp);
  44.     status |= chk(got, (long)'a', "fgetc(fp)");
  45.  
  46.     fseek(fp,150L,0);
  47.     got = fgetc(fp);
  48.     status |= chk(got, 0L, "fgetc(fp)@150");
  49.  
  50.     fclose(fp);
  51.     unlink(FILENAME);
  52.  
  53.     return status;
  54. }
  55.